import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STComponent, STColumn, STRequestOptions, STChange } from '@delon/abc/st';
import { SFComponent, SFSchema, SFDateWidgetSchema } from '@delon/form';
import { NzModalService } from 'ng-zorro-antd/modal';
import { TicketService } from '../../../services/ticket.service';

@Component({
  selector: 'app-add-cart',
  templateUrl: './add-cart.component.html'
})
export class AddCartComponent implements OnInit {
  data = [];
  selectedData: any[] = [];
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  columns: STColumn[] = [
    { title: '', index: 'key', type: 'checkbox' },
    { title: '车牌号', index: 'carNo' },
    { title: '车辆所有人', index: 'carOwner' }
  ];
  searchSchema: SFSchema = {
    properties: {
      carNo: {
        title: '',
        type: 'string',
        ui: {
          placeholder: '请输入车牌号'
        }
      },
      carOwner: {
        title: '',
        type: 'string',
        ui: {
          placeholder: '请输入车辆所有人'
        }
      }
    }
  };

  constructor(public service: TicketService, private nzModalService: NzModalService, private router: Router) {}

  ngOnInit(): void {}

  beforeReq = (requestOptions: STRequestOptions) => {
    if (this.sf) {
      Object.assign(requestOptions.body, {
        ...this.sf?.value
      });
    }
    return requestOptions;
  };

  afterRes = (data: any[], rawData?: any) => {
    return data.map(item => ({ ...item, disabled: item.isWhiteList }));
  };

  stChange(e: STChange): void {
    switch (e.type) {
      case 'checkbox':
        this.selectedData = e.checkbox!;
        break;
    }
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
  }
}
